<template>
  <div class="app-container">
    <el-form :inline="true" :model="subject" class="demo-form-inline">
      <h2>仅添加一级分类</h2>
      <el-form-item label="添加一级分类">
        <el-input v-model="subject.onlyOneSubject" placeholder="一级分类"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">添加</el-button>
      </el-form-item>
    </el-form>


    <el-form :inline="true" :model="subject" class="demo-form-inline">
      <h2>仅添加二级分类</h2>
      <el-form-item label="一级分类">
        <el-select v-model="subject.oneSubjectId" placeholder="请选择一级分类">
          <el-option v-for="oneSubject in oneSubjectList" :label="oneSubject.title" :value="oneSubject.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-input v-model="subject.twoSubject" placeholder="二级分类"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">添加</el-button>
      </el-form-item>
    </el-form>

    <el-form :inline="true" :model="subject" class="demo-form-inline">
      <h2>添加一级二级分类</h2>
      <el-form-item label="一级分类">
        <el-input v-model="subject.oneSubjectAdd" placeholder="一级分类"></el-input>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-input v-model="subject.twoSubjectAdd" placeholder="二级分类"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">添加</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
  import subject from '@/api/subject'
    export default {
        name: "save.vue",
      data(){
          return{
            subject:{},//分类添加对象
            oneSubjectList:[]//一级分类集合
          }
      },
      created() {
          //查询所有一级分类
        this.getOneSubject()

      },
      methods:{
          //查询所有一级分类
        getOneSubject(){
          subject.getOneSubject()
            .then(response=>{
              this.oneSubjectList = response.data.list
            })
        },
        //添加课程分类
        onSubmit(){
          subject.addSubject(this.subject)
            .then(response=>{
              this.$message({
                type: 'success',
                message: '添加成功!'
              });
              //跳转到课程分类显示页面
              this.$router.push({path:'/subject/index'})
            })
        }
      }
    }
</script>

<style scoped>

</style>
